package br.inf.solutions.apresentacoes.ssp.control.validator;

import java.util.List;
import java.util.Map;

import br.com.vexillum.control.validator.Validator;
import br.com.vexillum.util.Return;
import br.inf.solutions.apresentacoes.ssp.model.ItensScalesServices;
import br.inf.solutions.apresentacoes.ssp.model.Person;
import br.inf.solutions.apresentacoes.ssp.model.ScaleService;
import br.inf.solutions.apresentacoes.ssp.model.basics.FunctionScale;

public class ScaleServiceValidator extends Validator {

	public ScaleServiceValidator(Map<String, Object> mapData) {
		super(mapData);
	}

	public Return validateInsertItemScale() {
		Return ret = new Return(true);

		Person person = (Person) mapData.get("person");
		FunctionScale functionScale = (FunctionScale) mapData
				.get("thisFunctionScale");

		ScaleService scaleService = (ScaleService) mapData.get("entity");
		List<ItensScalesServices> itens = scaleService.getItemScalesServices();
		if (person != null && functionScale != null) {
			for (ItensScalesServices itensScalesServices : itens) {
				if (Double.compare(itensScalesServices.getPerson().getRg(),
						person.getRg()) == 0)
					ret.concat(creatReturn(
							null,
							getValidationMessage(null, "person_exists_scale",
									false)));
			}
		}

		ret.concat(validateSave());
		if (person == null)
			ret.concat(creatReturn(
					"itemFunctionScales",
					getValidationMessage("itemFunctionScales", "notNull", false)));
		if (functionScale == null)
			ret.concat(creatReturn("itemPersonScales",
					getValidationMessage("itemPersonScales", "notNull", false)));

		return ret;
	}

	public Return validateSearchScaleService() {
		Return ret = new Return(true);

		ScaleService scaleService = (ScaleService) entity;

		if (scaleService.getBoutService() == null
				&& scaleService.getTypeScaleService() == null)
			ret.concat(creatReturn(null,
					getValidationMessage(null, "searchbycriteria", false)));

		return ret;
	}
}
